package com.v1.lo;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import com.v1.model.CategoryWapper;
import com.v1.model.ItemWapper;
import com.v1.model.Tag;

@Service("CategoryTran")
public class CategoryTranImpl extends BaseLO implements CategoryTran {

	public void addCategoryTran(CategoryWapper categoryWapper) {

		int categoryid = (Integer) insert(categoryWapper, Statement.Category_addCate);
		List<ItemWapper> items = categoryWapper.getItems();
		for (ItemWapper itemWapper : items) {
			itemWapper.setCategoryid(categoryid);
			itemWapper.setType(0);
			int itemid = (Integer) insert(itemWapper, Statement.Item_addItem);
			itemWapper.setItemid(itemid);
			itemWapper.setScore(0);
			insert(itemWapper, Statement.Item_addItemdetail);
			List<Tag> tags = itemWapper.getTags();
			if (CollectionUtils.isNotEmpty(tags)) {
				for (Tag tag : tags) {
					tag.setCategoryid(categoryid);
					tag.setItemid(itemid);
					insert(tag, Statement.Tag_addTag);
				}
			}
		}
	}

}
